package com.sxt.business.controller;


import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sxt.business.domain.Provider;
import com.sxt.business.service.IProviderService;
import com.sxt.business.vo.ProviderVO;
import com.sxt.system.controller.DeptController;
import com.sxt.system.utils.DataGridView;
import com.sxt.system.utils.ResultObj;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 俊哥
 * @since 2019-11-15
 */
@RestController
@RequestMapping("provider")
public class ProviderController {

	@Autowired
	private IProviderService providerService;
	
	private Log log = LogFactory.getLog(DeptController.class);
	
	/**
	 * 	全查询
	 * @param providerVO
	 * @return
	 */
	@RequestMapping("loadAllProvider")
	public DataGridView loadAllProvider(ProviderVO providerVO) {
		return this.providerService.loadAllProvider(providerVO);
	}
	
	/**
	 * 	添加
	 */
	@RequestMapping("addProvider")
	public ResultObj addProvider(Provider provider ,HttpSession session) {
		try {
			providerService.addProvider(provider);
			return ResultObj.ADD_SUCCESS;
		} catch (Exception e) {
			log.error("添加失败");
			return ResultObj.ADD_ERROR;
		}
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("updateProvider")
	public ResultObj updateProvider(Provider provider) {
		try {
			providerService.updateProvider(provider);
			return ResultObj.UPDATE_SUCCESS;
		} catch (Exception e) {
			log.error("修改失败");
			return ResultObj.UPDATE_ERROR;
		}
	}
	
	/**
	 * 	删除
	 */
	@RequestMapping("deleteProvider")
	public ResultObj deleteProvider(Integer id) {
		try {
			providerService.removeById(id);
			return ResultObj.DELETE_SUCCESS;
		} catch (Exception e) {
			log.error("删除失败");
			return ResultObj.DELETE_ERROR;
		}
	}
	
	/**
	 * 批量删除
	 */
	@RequestMapping("batchDeleteProvider")
	public ResultObj batchDeleteProvider(Integer [] ids) {
		try {
			if(ids==null||ids.length==0) {
				log.error("参数不能为空");
				return ResultObj.DELETE_ERROR;
			}
			//Collection<Serializable> idList = new ArrayList<Serializable>();
			for (Integer  integer  : ids) {
				//idList.add(integer);
				this.providerService.removeById(integer);
			}
			//this.providerService.removeByIds(idList);
			return ResultObj.DELETE_SUCCESS;
		} catch (Exception e) {
			log.error("删除失败");
			return ResultObj.DELETE_ERROR;
		}
	}
	
	/**
	 * 加载可以的供养商不分页
	 */
	@RequestMapping("loadAllAvailableProvider")
	public DataGridView loadAllAvailableProvider() {
		return this.providerService.loadAllAvailableProvider();
	}
}

